﻿int[] arr = new int[] {4,9,8,7,2,1,3,6,4,5};//输入数组
for (int j = 0; j < arr.Length; j++)
{
    bool exchanged = false;//事件：交换
    //一轮
    for (int i = 0; i < arr.Length - 1; i++)
    {
        //判断一轮中是否发生交换
        if (arr[i] > arr[i + 1])
        {
            int temp = arr[i];//暂时存放大者
            arr[i] = arr[i + 1];//小者放前
            arr[i + 1] = temp;//大者放后
            exchanged = true;//交换发生
        }
    }
    //一轮中无交换则不再交换
    if(exchanged == false)
    {
        break;//跳出循环
    }
    //遍历
    for (int k = 0; k < arr.Length; k++)
    {
        Console.Write(arr[k] + "\t");//依次输出
    }
    Console.WriteLine();//隔行
    //分割线
    Console.WriteLine("-------------------------------------------------------------------------");
}